package es.ats.codington.web.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.domain.LargeBusiness;
import es.ats.codington.festival.domain.Museum;
import es.ats.codington.festival.domain.Park;
import es.ats.codington.festival.domain.Place;
import es.ats.codington.festival.domain.Stadium;
import es.ats.codington.festival.domain.Theater;
import es.ats.codington.festival.domain.TouristAtracction;
import es.ats.codington.festival.domain.TraditionalMarkets;
import es.ats.codington.festival.domain.Zoo;
import es.ats.codington.festival.services.EventService;
import es.ats.codington.festival.services.PlaceService;

/**
 * Servlet implementation class CreateEventServlet
 */
@WebServlet("/CreatePlaceServlet")
public class CreatePlaceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public enum TypeName{Stadium, LargeBusiness, Theater, Museum, TraditionalMarkets,Zoo,TouristatrAcction,Park}
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreatePlaceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");  

		String nameplace=request.getParameter("nameplace");
		String description=request.getParameter("descriptions");
		String address=request.getParameter("address");
		int capacity=Integer.parseInt(request.getParameter("capacity"));
		String type=request.getParameter("type");

		try{
			boolean tt = false;
			PlaceService ps = new PlaceService();
			
			switch(TypeName.valueOf(type)){
			
			case Stadium:  
				
				Stadium stadium=new Stadium();
				stadium.setName(nameplace);
				stadium.setAddress(address);
				stadium.setDescription(description);
				stadium.setCapacity(capacity);
				stadium.setTown("North");
				stadium.setType(type);
				tt = ps.createPlace(stadium);
				

				break;
				
			case LargeBusiness:
				
				LargeBusiness largebusiness = new LargeBusiness();
				largebusiness.setName(nameplace);
				largebusiness.setAddress(address);
				largebusiness.setDescription(description);
				largebusiness.setCapacity(capacity);
				largebusiness.setTown("North");
				largebusiness.setType(type);
				tt = ps.createPlace(largebusiness);
				
				
				break;
				
			case Theater:
				
				Theater theater = new Theater();
				theater.setName(nameplace);
				theater.setAddress(address);
				theater.setDescription(description);
				theater.setCapacity(capacity);
				theater.setTown("North");
				theater.setType(type);
				tt = ps.createPlace(theater);
				
				
				break;
				
			case  Museum:
				
				Museum museum = new Museum();
				museum.setName(nameplace);
				museum.setAddress(address);
				museum.setDescription(description);
				museum.setCapacity(capacity);
				museum.setTown("North");
				museum.setType(type);
				tt = ps.createPlace(museum);
				
				
				break;
				
			case TraditionalMarkets:
				
				TraditionalMarkets traditionalmarkets = new TraditionalMarkets();
				traditionalmarkets.setName(nameplace);
				traditionalmarkets.setAddress(address);
				traditionalmarkets.setDescription(description);
				traditionalmarkets.setCapacity(capacity);
				traditionalmarkets.setTown("South");
				traditionalmarkets.setType(type);
				tt = ps.createPlace(traditionalmarkets);
				
				
				break;
				
			case Zoo:
				
				Zoo zoo = new Zoo();
				zoo.setName(nameplace);
				zoo.setAddress(address);
				zoo.setDescription(description);
				zoo.setCapacity(capacity);
				zoo.setTown("South");
				zoo.setType(type);
				tt = ps.createPlace(zoo);
				
				
				break;
				
			case TouristatrAcction:
				
				TouristAtracction touristatracction = new TouristAtracction();
				touristatracction.setName(nameplace);
				touristatracction.setAddress(address);
				touristatracction.setDescription(description);
				touristatracction.setCapacity(capacity);
				touristatracction.setTown("South");
				touristatracction.setType(type);
				tt = ps.createPlace(touristatracction);
				
				
				break;
				
			case Park:
				
				Park park = new Park();
				park.setName(nameplace);
				park.setAddress(address);
				park.setDescription(description);
				park.setCapacity(capacity);
				park.setTown("South");
				park.setType(type);
				tt = ps.createPlace(park);
				
				
				break;
					
			default: 
				
					break;
			}
				       
 		    if (tt==true){	
 		
 		    RequestDispatcher rd=request.getRequestDispatcher("mainpageadmin.jsp");  
 		    rd.forward(request,response);
 		    
 		    }else{
 		    	  
 		         RequestDispatcher rd2=request.getRequestDispatcher("createplace.jsp");  
 		         rd2.forward(request,response);  
 		         }
 	    }catch(Exception ex){
 			ex.getMessage();
 		}     
 		    
 
	          
	}

}

